rebase with preserve dates opt#96
Conversation
cedf847 to
c46e74e
Compare
276321f to
5531d74
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in gh stack rebase flag (--committer-date-is-author-date with --preserve-dates alias) and threads it through the git layer so all cascade rebase operations can keep committer dates equal to author dates (improving SHA stability for identical rebases).
Changes:
- Introduces
git.RebaseOptsand updates git ops/wrappers/mocks to forward--committer-date-is-author-dateintogit rebaseinvocations (including continue/auto-resolve paths). - Adds CLI flags to
gh stack rebase, persists the choice inrebaseState, and restores it on--continue. - Updates tests and documentation to cover flag passthrough, aliasing, and state round-tripping.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new rebase flag and adds an example invocation. |
| docs/src/content/docs/reference/cli.md | Updates the CLI reference to include the new rebase flag and example. |
| internal/git/gitops.go | Adds RebaseOpts, updates Ops interface/default implementation to pass the new flag to git rebase. |
| internal/git/git.go | Threads RebaseOpts through public wrappers and rebase continue/auto-resolve helpers. |
| internal/git/mock_ops.go | Updates mock signatures to match the new RebaseOpts-accepting APIs. |
| cmd/rebase.go | Registers the new flags, persists/restores them via rebaseState, and forwards to cascade/continue. |
| cmd/utils.go | Threads the new option through cascade rebase calls (Rebase/RebaseOnto). |
| internal/modify/apply.go | Updates callers to pass zero-value git.RebaseOpts{}. |
| internal/modify/apply_test.go | Updates mock function signatures for the new git rebase APIs. |
| cmd/sync_test.go | Updates mock function signatures for the new git rebase APIs. |
| cmd/rebase_test.go | Adds/updates tests to validate flag passthrough, alias behavior, and state persistence. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 11/11 changed files
- Comments generated: 3
Introduce an opt-in `--committer-date-is-author-date` flag (with
`--preserve-dates` alias) for `gh stack rebase`. The flag is passed
through to every underlying `git rebase` invocation in the cascade,
keeping committer dates equal to author dates so that identical content
rebased onto an identical parent produces stable SHAs. This reduces
spurious force-push notifications and noisy review timelines, especially
in deep stacks where bottom branches get re-rebased on every merge.
Git layer changes:
- Add `RebaseOpts` struct with `CommitterDateIsAuthorDate` field to
`internal/git/gitops.go`
- Update `Ops` interface, `defaultOps`, public wrappers, and
`rebaseContinueOnce`/`tryAutoResolveRebase` helpers to accept and
forward the flag
- Update `MockOps` to match the new signatures
Command layer changes:
- Register `--committer-date-is-author-date` and `--preserve-dates`
flags on the cobra command in `cmd/rebase.go`
- Add `CommitterDateIsAuthorDate` to `cascadeRebaseOpts` and thread it
to all `git.Rebase`/`git.RebaseOnto` calls in `cmd/utils.go`
- Persist the flag in `rebaseState` JSON so `--continue` resumes with
the same behavior; pass it to `RebaseContinue` and subsequent cascade
calls
- Update `internal/modify/apply.go` callers to pass zero-value
`RebaseOpts{}`
Tests:
- Update all existing mock signatures in rebase, sync, and modify tests
- Add tests for flag passthrough, `--preserve-dates` alias, state
round-trip, `--continue` flag restoration, and conflict state
persistence
Docs:
- Update flag tables and examples in README.md and
docs/src/content/docs/reference/cli.md
5531d74 to
6daa31f
Compare
ktravers
left a comment
There was a problem hiding this comment.
Looks good, left one question about naming (not blocking)
| | `--continue` | Continue the rebase after resolving conflicts | | ||
| | `--abort` | Abort the rebase and restore all branches to their pre-rebase state | | ||
| | `--remote <name>` | Remote to fetch from (defaults to auto-detected remote) | | ||
| | `--committer-date-is-author-date` | Set the committer date to the author date during rebase. Alias: `--preserve-dates` | |
There was a problem hiding this comment.
Wondering if there's a name that better reflects why this option exists, as opposed to literally what it's doing 🤔
The alias is pretty close. Any reason to not just use that and drop the lengthier --committer-date-is-author-date altogether? Or keep that as an internal only name?
There was a problem hiding this comment.
Yeah it's unfortunate that the official flag in git is so long. Fwiw git's alias to --committer-date-is-author-date is --ignore-date, which I personally find very confusing. I opted to go with --preserve-dates as an alias because it is what made the most intuitive sense to me.
The intention of the command is to not change the committed date (and sometimes the commit sha, but only if the committer is also the author, among other conditions). I've thought about flipping the order so --preserve-dates is the primary and --committer-date-is-author-date is the alias, but imo aliases are generally supposed to be shorter and less detailed.
I don't love the naming, but I can't think of a better option either. Hoping that we can get this into users' hands and they can give us feedback on what makes sense or not 😅
Add --committer-date-is-author-date flag to gh stack rebase
Introduce an opt-in
--committer-date-is-author-dateflag (with--preserve-datesalias) forgh stack rebase. The flag is passedthrough to every underlying
git rebaseinvocation in the cascade,keeping committer dates equal to author dates so that identical content
rebased onto an identical parent produces stable SHAs. This reduces
spurious force-push notifications and noisy review timelines, especially
in deep stacks where bottom branches get re-rebased on every merge.
Git layer changes:
RebaseOptsstruct withCommitterDateIsAuthorDatefield tointernal/git/gitops.goOpsinterface,defaultOps, public wrappers, andrebaseContinueOnce/tryAutoResolveRebasehelpers to accept andforward the flag
MockOpsto match the new signaturesCommand layer changes:
--committer-date-is-author-dateand--preserve-datesflags on the cobra command in
cmd/rebase.goCommitterDateIsAuthorDatetocascadeRebaseOptsand thread itto all
git.Rebase/git.RebaseOntocalls incmd/utils.gorebaseStateJSON so--continueresumes withthe same behavior; pass it to
RebaseContinueand subsequent cascadecalls
internal/modify/apply.gocallers to pass zero-valueRebaseOpts{}Tests:
--preserve-datesalias, stateround-trip,
--continueflag restoration, and conflict statepersistence
Docs:
docs/src/content/docs/reference/cli.md
Stack created with GitHub Stacks CLI • Give Feedback 💬